package com.guisu.animation.loading.three_circle_loading

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View

class CircleView: View {

    private val mPaint by lazy { Paint() }
    private var mColor = 0

    constructor(context: Context): this(context, null)
    constructor(context: Context, attrs: AttributeSet?): this(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr) {
        mPaint.apply {
            isAntiAlias = true
            isDither = true
        }
    }

    override fun onDraw(canvas: Canvas) {
        // 画背景圆形  三个参数  cx  cy  半径  画笔
        val cx = width / 2f
        val cy = height / 2f
        canvas.drawCircle(cx, cy, cx, mPaint)
    }

    /**
     * 切换颜色
     */
    fun exchangeColor(color: Int) {
        mColor = color
        mPaint.color = color
        invalidate()
    }

    /**
     * 获取当前颜色
     */
    fun getColor() = mColor
}